﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="BugSysSolution.Register" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="Style/site.css" rel="stylesheet" type="text/css" />
    <script src="Javascript/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="Javascript/common.js" type="text/javascript"></script>
    <script src="Javascript/CheckForm.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
        <table id="tab1" class="tab">
            <tr><td colspan="2"><b>用户注册</b></td></tr>
            <tr>
                <td>用户名:</td>
                <td><input type="text" id="txt_uid" size="30" /><span id="span1"></span></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="text" id="txt_pwd" size="30" onkeydown="changepwd(event,this);" onkeyup="showpwd(this);"/></td>
            </tr>
            <tr>
                <td>邮箱:</td>
                <td><input type="text" id="txt_email" size="30" /></td>
            </tr>
            <tr>
                <td>QQ:</td>
                <td><input type="text" id="txt_qq" size="30"/></td>
            </tr>
            <tr>
                <td>真实姓名:</td>
                <td><input type="text" id="txt_realName" size="30" /></td>
            </tr>
            <tr>
                <td>爱好:</td>
                <td><input type="text" id="txt_hobby" size="30" /></td>
            </tr>
            <tr>
                <td>微薄:</td>
                <td><input type="text" id="txt_sinaweibo" size="30" /></td>
            </tr>
            <tr>
                <td align="center" colspan="2"><input type="button" class="btn" id="btnok" value="注册"/></td>
            </tr>
    </table>
    </form>
</body>
</html>
<script type="text/javascript">
    var requestAjaxUrl = "../RequestAjaxPage/UserAjaxPage.aspx";

    //输入密码改变成*的事件
    var temppwd = "";
    var realpwd = "";
    function changepwd(e,obj) {
        temppwd += "*";
        var currKey = 0;
        var e = e || event;
        currKey = e.keyCode || e.which || e.charCode;
        if (currKey == 8) {
            temppwd = temppwd.substring(0, temppwd.length - 2);
            realpwd = realpwd.substring(0, realpwd.length - 1);
        }
        else {
            realpwd += String.fromCharCode(currKey);
        }
    }

    function showpwd(obj) {
        $(obj).val(temppwd);
    }

    //ajax验证用户名是否存在
    $("#txt_uid").focusout(function () {
        SendAjax("post", requestAjaxUrl, { tag: 'checkuid', ran: Math.random(), uid: $("#txt_uid").val() }, function (data) {
            if (data == "Error") {
                return;
            }
            else {
                $("#span1").css("color", "green").text(data.split('|')[1]);
            }
        })
    })

    $("#btnok").click(function () {
        var result = checkForm();
        if (result != "") {
            alert(result);
            return;
        }

        SendAjax("post", requestAjaxUrl, { tag: 'adduser', uid: $("#txt_uid").val(), PassWord: realpwd, Email: $("#txt_email").val(), QQ: $("#txt_qq").val(), RealName: $("#txt_realName").val(), Hobby: $("#txt_hobby").val(), Sinaweibo: $("#txt_sinaweibo").val(), ran: Math.random() },"", function (data) {
            if (data == "") {
                return;
            }
            else {
                if (data.split('|')[0] == "0") {
                    $("#loginName").val($("#txt_uid").val());
                    $("#loginPwd").val($("#txt_pwd").val());
                    //$.FrameDialog.closeDialog(fid);
                    window.close();
                }
                else {
                    alert(data.split('|')[1]);
                }
            }
        })
    })

    function checkForm() {
        var msg = "";
        if ($("#txt_uid").val().length == 0) {
            msg += "用户名不允许为空!";
            return msg;
        }
        if ($("#span1").text() == "") {
            msg += "请先验证用户名!";
            return msg;
        }
        if ($("#span1").text() != "" && $("#span1").css("color") == "rgb(255, 0, 0)") {
            msg += "用户名已存在!";
            return msg ;
        }
        if ($("#txt_uid").val() == "") {
            msg += "用户名不允许为空!";
            return msg;
        }
        if ($("#txt_pwd").val() == "") {
            msg += "密码不允许为空!";
            return msg;
        }
        if ($("#txt_email").val() != "") {
            if (!CheckForm.isEmail($("#txt_email").val())) {
                msg += "邮箱格式不正确!";
                return msg;
            }
        }
        if ($("#txt_qq").val() != "") {
            if (!CheckForm.IsPositiveInteger($("#txt_qq").val()) || $("#txt_qq").val().length < 6 || $("#txt_qq").val().length > 15) {
                msg += "qq号码格式不正确!";
                return msg;
            }
        }
        if ($("#txt_realName").val() != "") {
            if (!CheckForm.CheckSpecialStr($("#txt_realName").val())) {
                msg += "真实姓名不允许为特殊字符!";
                return msg;
            }
        }
        return msg;
    }
</script>